<a title="new type" class="iframe-fancy" href="actions/structures.php?sid=<?=$GLOBALS['MAIN']->site->id ?>&action=new_type">New type</a>

<?foreach ($result as $type):
    $has_block = false;
    if (empty($type['structures'])) {
        $type['structures'][] = array();
    }
    ?>
    <div class="hub">
        <div class="title"><?= $type['title'] ?></div>
        <? foreach ($type['structures'] as $structure): ?>
            <ul><? if (empty($structure)):
                ?><li>
                        <? if (!$has_block): ?>
                            <div class="container type">
                                <div class="item-title">Title:<?= $type['title'] ?></div>
                                <a title="[<?= $type['title'] . "]:new structure" ?>" class="button iframe-fancy" href="actions/structures.php?tid=<?= $type['id'] ?>&action=new_structure">New structure</a>
                                <a title="Edit [<?= $type['title'] . "]" ?>" class="button iframe-fancy" href="actions/structures.php?tid=<?= $type['id'] ?>&action=edit_type">Edit type</a>
                                <a title="Delete [<?= $type['title'] . "]" ?>" class="button iframe-fancy" href="actions/structures.php?tid=<?= $type['id'] ?>&action=delete_type">Delete type</a>
                            </div>
                            <? $has_block = true;
                        endif;
                        ?>
                    </li><? else:
                        ?><li>
            <? if (!$has_block): ?>
                            <div class="container type">
                                <div class="item-title">Title:<?= $type['title'] ?></div>
                                <div class="item-title">Structures:<?= count($type['structures']) ?></div>
                                <a title="[<?= $type['title'] . "]:new structure" ?>" class="button iframe-fancy" href="actions/structures.php?tid=<?= $type['id'] ?>&action=new_structure">New structure</a>
                                <a title="Edit [<?= $type['title'] . "]" ?>" class="button iframe-fancy" href="actions/structures.php?tid=<?= $type['id'] ?>&action=edit_type">Edit type</a>
                                <a title="Delete [<?= $type['title'] . "]" ?>" class="button iframe-fancy" href="actions/structures.php?tid=<?= $type['id'] ?>&action=delete_type">Delete type</a>
                            </div>
                            <? $has_block = true;
                        else:
                            ?>
                            <div class="container empty">Up</div>
            <? endif; ?></li><li>
                        <div class="container structure">
                            <div class="item-title">Title: <?= $structure['title'] ?></div>
                            <div class="item-code">Blocks: <?= count($structure['blocks']); ?></div>
                            <a title="[<?= $type['title'] . "]:[" . $structure['title'] ?>]:new block" class="button iframe-fancy" href="actions/structures.php?sid=<?= $structure['id'] ?>&action=new_block">New Block</a>
                            <a title="Delete [<?= $type['title'] . "]:[" . $structure['title'] ?>]"class="button iframe-fancy" href="actions/structures.php?sid=<?= $structure['id'] ?>&action=delete_structure">Delete structure</a>
                            <a title="Edit [<?= $type['title'] . "]:[" . $structure['title'] ?>]" class="button iframe-fancy" href="actions/structures.php?sid=<?= $structure['id'] ?>&action=edit_structure">Edit structure</a>
                        </div>
                    </li><? foreach ($structure['blocks'] as $block): ?><li>
                            <div class="container block">
                                <div class="item-title">Title: <?= $block['title'] ?></div>
                                <div class="item-code"><a href="content.php?bid=<?=$block['id']?>">Elements and sections:</a></div>
                                <a title="Delete [<?= $type['title'] . "]:[" . $block['title'] . "]:[" . $block['title'] ?>]"class="button iframe-fancy" href="actions/structures.php?bid=<?= $block['id'] ?>&action=delete_block">Delete block</a>
                                <a title="Edit [<?= $type['title'] . "]:[" . $structure['title'] . "]:[" . $block['title'] ?>]" class="button iframe-fancy" href="actions/structures.php?bid=<?= $block['id'] ?>&action=edit_block">Edit block</a>
                                <a title="Edit [<?= $type['title'] . "]:[" . $structure['title'] . "]:[" . $block['title'] ?>]:section fields" class="button iframe-fancy" href="actions/structures.php?bid=<?= $block['id'] ?>&action=section_fields">Section filelds</a>
                                <a title="Edit [<?= $type['title'] . "]:[" . $structure['title'] . "]:[" . $block['title'] ?>]:element fields" class="button iframe-fancy" href="actions/structures.php?bid=<?= $block['id'] ?>&action=element_fields">Element filelds</a>
                            </div>
                        </li><? endforeach; ?>
            <? endif; ?>
            </ul>
    <? endforeach; ?>
    </div>
<? endforeach; ?>
    